From a5971d3fe76be19d55f4032461d1acb77ece8d04 Mon Sep 17 00:00:00 2001
From: orbea <orbea@riseup.net>
Date: Mon, 15 Nov 2021 11:31:49 -0800
Subject: [PATCH] Allow installing the database

---
 CMakeLists.txt | 6 ++++--
 sdl2-jstest.c  | 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index f70d26e..b651581 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -29,8 +29,7 @@ include(GetProjectVersion)
 include(GNUInstallDirs)
 
 add_definitions(-DSDL_JSTEST_VERSION="${PROJECT_VERSION}")
-
-include(GNUInstallDirs)
+add_definitions(-DGAMECONTROLLERDB="${CMAKE_INSTALL_FULL_DATADIR}/sdl-jstest/gamecontrollerdb.txt")
 
 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
 
@@ -107,6 +106,9 @@ if(BUILD_SDL2_JSTEST)
   install(FILES ${CMAKE_CURRENT_BINARY_DIR}/sdl2-jstest.1
     DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
 
+  install(FILES ${CMAKE_CURRENT_BINARY_DIR}/gamecontrollerdb.txt
+    DESTINATION ${CMAKE_INSTALL_DATADIR}/sdl-jstest)
+
   install(TARGETS sdl2-jstest
     RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
 endif()
diff --git a/sdl2-jstest.c b/sdl2-jstest.c
index 61e95ea..94c402f 100644
--- a/sdl2-jstest.c
+++ b/sdl2-jstest.c
@@ -579,7 +579,7 @@ int main(int argc, char** argv)
     atexit(SDL_Quit);
 
     {
-      int ret = SDL_GameControllerAddMappingsFromFile("gamecontrollerdb.txt");
+      int ret = SDL_GameControllerAddMappingsFromFile(GAMECONTROLLERDB);
       if (ret < 0)
       {
         fprintf(stderr, "error: failed to read gamecontrollerdb.txt: %s\n", SDL_GetError());
-- 
2.29.2
